<%--@elvariable id="webRoot" type="com.doupi.partner.op.interceptor.OpFilter"--%>
<%@ page language="java" pageEncoding="UTF-8" %>
<%@ include file="../../common/tags.jsp" %>

<!DOCTYPE html>
<html>
<head lang="en">
    <%@include file="../../common/assets.jsp" %>
    <link type="text/css" rel="stylesheet" href="${webRoot }/assets/ui/amazeui/tree/amazeui.tree.min.css">
</head>
<body>
<!-- header -->
<%@include file="../../common/header.jsp" %>

<!-- main start -->
<div class="am-cf admin-main">
    <!-- sidebar start -->
    <%@include file="../../common/menu.jsp" %>
    <!-- sidebar end -->

    <!-- main start -->
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf">
                    <strong class="am-text-primary am-text-lg">系统配置</strong> /
                    <small>系统参数编辑</small>
                </div>
            </div>

            <hr>
            <form action="${webRoot}/configure/systemConfig/save" method="POST" id="systemConfig-edit-form">

                <div class="am-tabs am-margin" data-am-tabs="">
                    <ul class="am-tabs-nav am-nav am-nav-tabs">
                        <li class="am-active">
                            <a href="#tab-base-info">基本信息</a>
                        </li>
                    </ul>


                    <div class="am-tabs-bd" style="touch-action: pan-y; -webkit-user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);">

                        <%--基本信息--%>
                        <div class="am-tab-panel am-in am-active am-form" id="tab-base-info">
                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">父类</div>
                                <div class="am-u-sm-8 am-u-md-10">
                                    <input type="hidden" class="am-input-sm" name="parentKey" value="${systemConfig.parentKey}">

                                    <ul class="am-tree am-tree-folder-select" role="tree" id="parentTree">
                                        <li class="am-tree-branch am-hide" data-template="treebranch" role="treeitem" aria-expanded="false">
                                            <div class="am-tree-branch-header">
                                                <button type="button" class="am-tree-icon am-tree-icon-caret am-icon-caret-right">
                                                    <span class="am-sr-only">Open</span>
                                                </button>
                                                <button type="button" class="am-tree-branch-name">
                                                    <span class="am-tree-icon am-tree-icon-folder"></span>
                                                    <span class="am-tree-label"></span>
                                                </button>
                                            </div>
                                            <ul class="am-tree-branch-children" role="group"></ul>
                                            <div class="am-tree-loader" role="alert">Loading...</div>
                                        </li>
                                        <li class="am-tree-item am-hide" data-template="treeitem" role="treeitem">
                                            <button type="button" class="am-tree-item-name">
                                                <span class="am-tree-icon am-tree-icon-item"></span>
                                                <span class="am-tree-label"></span>
                                            </button>
                                        </li>
                                    </ul>

                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">KEY</div>
                                <div class="am-u-sm-8 am-u-md-10">
                                    <input type="text" class="am-input-sm" name="key" value="${systemConfig.key}">
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">名称</div>
                                <div class="am-u-sm-8 am-u-md-10">
                                    <input type="text" class="am-input-sm" name="name" value="${systemConfig.name}">
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">值</div>
                                <div class="am-u-sm-8 am-u-md-10">
                                    <input type="text" class="am-input-sm" name="value" value="${systemConfig.value}">
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">备注</div>
                                <div class="am-u-sm-8 am-u-md-10">
                                    <textarea rows="5" cols="50" class="am-input-sm" name="memo">${systemConfig.memo}</textarea>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>

                <div class="am-margin">
                    <button type="submit" class="am-btn am-btn-primary am-btn-xs">保存</button>
                    <button type="button" class="am-btn am-btn-primary am-btn-xs" onclick="history.go(-1)">关闭</button>
                </div>
            </form>
        </div>

    </div>

    <!-- main end -->

    <%@include file="../../common/footer.jsp" %>

    <script src="${webRoot}/assets/ui/amazeui/tree/amazeui.tree.min.js"></script>

    <script type="text/javascript">
        $(function () {
            var flag = false;
            $('#parentTree').tree({
                dataSource: function (options, callback) {
                    ajaxRequest({
                        url: '${webRoot}/configure/systemConfig/list/' + ((options && options.attr && options.attr.code)
                        || '0'),
                        method: 'POST',
                        async: false
                    }, function (data) {
                        if (data.statusCode == '0000') {
                            var dataSources = [];
                            if (!flag) {
                                dataSources.push({
                                    title: '/',
                                    type: 'folder',
                                    attr: {
                                        id: 'systemConfig0',
                                        code: '0'
                                    }
                                });
                                flag = true;
                            } else {
                                $.each(data.data, function (key, value) {
                                    dataSources.push({
                                        title: value.name,
                                        type: 'folder',
                                        attr: {
                                            id: 'systemConfig' + value.key,
                                            code: value.key
                                        }
                                    });
                                });
                            }

                            callback({
                                data: dataSources
                            });
                        }
                    }, function () {
                    }, true);
                },
                multiSelect: false,
                cacheItems: true,
                folderSelect: true
            }).on('selected.tree.amui', function (event, selected) {
                $('input[name=parentKey]').val(selected.target.attr.code);
            }).on('deselected.tree.amui', function (event, selected) {
                $('input[name=parentKey]').val('0');
            });

            var keyPath = '${systemConfig.keyPath}';
            if (keyPath != '') {
                $.each(keyPath.split('/'), function (k, v) {
                    if (v != '') {
                        $('#parentTree').tree('openFolder', $('#systemConfig' + v));
                        $('#parentTree').tree('selectItem', $('#systemConfig' + v));
                    }
                });
            } else {
                $('#parentTree').tree('selectItem', $('#systemConfig0'));
            }
        });
    </script>
</body>
</html>